package com.ms.p2p.controller.admin;


import com.alibaba.dubbo.config.annotation.Reference;
import com.ms.common.bean.Message;
import com.ms.p2p.bean.PageBean;
import com.ms.p2p.controller.BaseController;
import com.ms.p2p.entity.account.BankCardImg;
import com.ms.p2p.entity.account.BankCardImgLog;
import com.ms.p2p.provider.BankCardImgProvider;
import com.ms.p2p.provider.MemberAccountBankProvider;
import com.ms.p2p.provider.UnBindProvider;
import com.ms.p2p.utils.JsonDataGridHelper;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;
import java.util.List;

/**
 * 用户银行卡信息
 */
@Controller("AdminBankUnbindController")
@RequestMapping({"/admin/bank/unbind"})
public class AdminBankUnbindController extends AdminBaseController {

    @Reference
    private UnBindProvider unBindProvider;

    @Reference
    private MemberAccountBankProvider accountBankProvider;

    @Reference
    private BankCardImgProvider bankCardImgProvider;
    @Reference
    private UnBindProvider bankCardLogProvider;

    @RequestMapping(value = {"/queryData"}, produces = {"application/json;charset=UTF-8"})
    @ResponseBody
    public PageBean queryData(HttpServletRequest request, HttpSession session
            , String userName, String userId,
                              PageBean page
    ) {

        page.setList(unBindProvider.unbindList());
        page.setTotalCount(10000);
        return JsonDataGridHelper.createJSONData(page);
    }
       @RequestMapping({"/list"})
    public String list(String userName, String userId) {
        return "admin/account/record/bankunbind/list";
    }
    @RequestMapping({"/view"})
    public String view(Integer id,HttpServletRequest request)

    {
        List<BankCardImg> list = bankCardImgProvider.findByLogId(id);
        request.setAttribute("images",list);
        request.setAttribute("id",id);
        return "admin/account/record/bankunbind/edit";
    }

    @RequestMapping({"/edit"})
    @ResponseBody
    public Message edit(Integer id, Integer status, HttpServletRequest request)

    {

        BankCardImgLog bankCardImgLog = bankCardLogProvider.findById(id);
        if(status==-1){
            bankCardImgLog.setStatus(-1);

        }else{
            bankCardImgLog.setStatus(1);
            accountBankProvider.delete(bankCardImgLog.getBank_id());
        }
        bankCardLogProvider.update(bankCardImgLog);

        List<BankCardImg> list = bankCardImgProvider.findByLogId(id);
        request.setAttribute("images",list);
        request.setAttribute("id",id);
       return Message.success("操作成功");
    }


    @Override
    public boolean getBinderFlag() {
        return true;
    }
}
